package com.shizhanzhe.zxbapp.team;

import android.content.ClipboardManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.PDDSC;
import com.shizhanzhe.zxbapp.bean.TeamMoney;
import com.shizhanzhe.zxbapp.bean.huoban;
import com.shizhanzhe.zxbapp.url.Path;
import com.shizhanzhe.zxbapp.utils.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zz9527 on 2019/1/18.
 */
public class ZhiShuAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private List<huoban.OneBean.DataBean> list=new ArrayList<>();
    private Context context;

    public ZhiShuAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void upData(List<huoban.OneBean.DataBean> list, int page) {
        if (list != null && !list.isEmpty()) {
            if (page == 1) {
                this.list = list;
            } else {
                this.list.addAll(list);
            }
            notifyDataSetChanged();
        }
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHold hold;

        if (view == null) {
            view = inflater.inflate(R.layout.adapter_team, null);
            hold = new ViewHold();
            hold.iv = view.findViewById(R.id.team_iv);
            hold.name = view.findViewById(R.id.team_name);
            hold.price = view.findViewById(R.id.team_money);
            view.setTag(hold);
        } else {
            hold = (ViewHold) view.getTag();
        }
        huoban.OneBean.DataBean bean = list.get(i);
        Glide.with(context).load(Path.img(bean.getAvatar())).apply(new RequestOptions().error(R.mipmap.logo).circleCrop()).into(hold.iv);
        hold.name.setText("ID:"+bean.getUid());
        if ("".equals(bean.getMobile())) {
            hold.price.setText("暂未绑定");
        } else {
            hold.price.setText(bean.getMobile());
        }
        hold.price.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                cm.setText(hold.price.getText().toString());
                return false;
            }
        });
        return view;
    }

    class ViewHold {
        ImageView iv;
        TextView name;
        TextView price;
    }

}
